home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / addmime.thor next >
Text File  |  1998-05-24  |  9KB  |  352 lines

  1. /*
  2.   $VER: AddMIME.thor 0.7 (29.11.96)
  3.   by Remco van Hooff
  4.  
  5.   Attach a file (MIME) while writing a msg in Thor.
  6.   Run from FSE, CED or GED.
  7.   Borrowed some code from InsertIt.thor (by Shaun Downend).
  8.  
  9.   HISTORY
  10.   0.2 - When the filerequester would be cancelled an empty attacment would be
  11.         created.
  12.       - No more requester/status bar stating DOC=xxx when using GoldED.
  13.  
  14.   0.3 - When the uploadpath for the current system is not defined the global
  15.         upload path is used.
  16.  
  17.   0.4 - Added multiple file attachment support (add, delete, edit).
  18.         NOTE: Only the first file, in a list of identical files, will be
  19.               edited (replaced), even when the the last of the identical files
  20.               was selected.
  21.       - Added reading of existing attacments.
  22.  
  23.   0.5 - Fixed an infinite loop occuring when only one file was selected and
  24.         no attachment was already present.
  25.  
  26.   0.6 - No more "Attachment:" text when saving an empty attachment string (no
  27.         attachments).
  28.       - Added archiving (LhA) of selected files.
  29.  
  30.   0.7 - Will not fail on archiving paths/files containing spaces anymore.
  31. */
  32.  
  33. lhaoptions = '-U8192 -a -b128 -x -r -e a' /* use the -q flag for no output */
  34. lhapath = 'c:'
  35.  
  36. /*!~ "Init" */
  37. OPTIONS RESULTS
  38. version = SUBWORD(SOURCELINE(2), 3,1)
  39. title = 'AddMIME' version '© by Remco van Hooff '
  40.  
  41. p=' '||ADDRESS()||' '||SHOW('P',,)
  42. IF POS(' THOR.',p)>0 THEN thorport=WORD(SUBSTR(p,POS(' THOR.',p)+1),1)
  43. ELSE DO
  44.   SAY 'THOR port not found!'
  45.   EXIT 10
  46. END
  47.  
  48. IF ~SHOW('p', 'BBSREAD') THEN DO
  49.   ADDRESS COMMAND
  50.   "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  51.   "WaitForPort BBSREAD"
  52. END
  53.  
  54. attachments = ''
  55. sep = '01'x
  56. /*~!*/
  57.  
  58. /*!~ "Get MSGFILE from editor" */
  59. editor.name.1     = 'GOLDED'
  60. editor.filename.1 = 'QUERY DOC VAR filename'
  61. editor.name.2     = 'THOR_FSE'
  62. editor.filename.2 = 'MSGFILENAME'
  63. editor.name.3     = 'rexx_ced'
  64. editor.filename.3 = 'status 21'
  65. editor.count = 3
  66.  
  67. DO n = 1 TO editor.count
  68.   IF(SUBSTR(ADDRESS(),1,LENGTH(editor.name.n)) = editor.name.n) THEN DO
  69.     editorport = address()
  70.     INTERPRET editor.filename.n
  71.     filename = RESULT
  72.     IF POS('/', filename) ~= 0 THEN filename = SUBSTR(filename, (LASTPOS('/', filename) + 1))
  73.   END
  74. END
  75.  
  76. IF editorport = '' THEN DO
  77.   SAY 'This script has to be run from your editor.'
  78.   SAY 'GoldED, FSE (Thor''s internal editor) and CygnusED are currently supported.'
  79.   EXIT
  80. END
  81. /*~!*/
  82.  
  83. /*!~ "Get system/event stuff" */
  84. ADDRESS(thorport)
  85. 'CURRENTBBS stem CURRENT'
  86. IF(RC ~= 0 | CURRENT.BBSNAME ~= "") THEN system = CURRENT.BBSNAME
  87. ELSE EXIT
  88.  
  89. ADDRESS(bbsread)
  90. 'GETBBSDATA "'system'" STEM BBSDATA'
  91. IF(RC ~= 0) THEN DO
  92.   ADDRESS(thorport)
  93.   'REQUESTNOTIFY TEXT "'BBSREAD.LASTERROR'" BT "_Ok"'
  94.   EXIT 5
  95. END
  96.  
  97. updir = BBSDATA.UPLOADPATH
  98.  
  99. IF  updir = '' THEN DO
  100.   'GETGLOBALDATA STEM GLOBAL'
  101.   IF(RC ~= 0) THEN DO
  102.     ADDRESS(thorport)
  103.     'REQUESTNOTIFY TEXT "'BBSREAD.LASTERROR'" BT "_Ok"'
  104.     EXIT 5
  105.   END
  106.   updir = GLOBAL.UPLOADPATH
  107. END
  108.  
  109. IF POS(':', updir) ~= length(updir) THEN updir = updir'/'
  110.  
  111. DO i = BBSDATA.FIRSTEVENT TO BBSDATA.LASTEVENT
  112.   DROP MSGTAGS. MSGDATA.
  113.   'READBREVENT BBSNAME "'system'" EVENTNR 'i' TAGSSTEM MSGTAGS DATASTEM MSGDATA'
  114.   IF(RC ~= 0) THEN DO
  115.     ADDRESS(thorport)
  116.     'REQUESTNOTIFY TEXT "'BBSREAD.LASTERROR'" BT "_Ok"'
  117.     EXIT 5
  118.   END
  119.   IF filename = MSGTAGS.MSGFILE THEN attachments = MSGTAGS.LOCALFILE
  120. END
  121. /*~!*/
  122.  
  123. CALL list_files(attachments)
  124.  
  125. EXIT
  126.  
  127. /*!~ "List_files"*/
  128. list_files:
  129.   att_files = ARG(1)
  130.   IF att_files = 'MSGTAGS.LOCALFILE' THEN att_files = ''
  131.   attach = 0
  132.  
  133.   IF att_files ~= '' THEN DO
  134.   parse_att_files = att_files
  135.     DO UNTIL parse_att_files = ''
  136.       attach = attach + 1
  137.       PARSE VAR parse_att_files atchfile '01'x parse_att_files
  138.       entry.attach = atchfile
  139.     END
  140.     attach = attach + 1
  141.     entry.attach = ''
  142.   END
  143.  
  144.   tot = attach + 1
  145.   entry.tot = 'Add'
  146.   tot = tot +1
  147.   entry.tot = 'Archive'
  148.   tot = tot +1
  149.   entry.tot = 'Accept'
  150.   entry.COUNT = tot
  151.  
  152.   ADDRESS(thorport)
  153.   'REQUESTLIST INSTEM' entry 'TITLE "'title'" SIZEGADGET'
  154.   IF (RC = 30) THEN DO
  155.     'REQUESTNOTIFY TEXT "'THOR.LASTERROR'" BT "_Ok"'
  156.     EXIT
  157.   END
  158.   IF RC = 5 THEN EXIT
  159.   ELSE DO
  160.     option = RESULT
  161.     IF UPPER(option) = 'ADD' THEN DO
  162.       addfile = add(att_files)
  163.       CALL list_files(addfile)
  164.     END
  165.     IF POS('ACCEPT', UPPER(option)) ~= 0 THEN CALL write_event(att_files)
  166.     IF POS('ARCHIVE', UPPER(option)) ~= 0 THEN DO
  167.       att_files = archive(att_files)
  168.       CALL list_files(att_files)
  169.     END
  170.     IF attach > 0 THEN DO
  171.       DO n = 1 TO attach - 1
  172.         IF option = entry.n THEN DO
  173.           'REQUESTNOTIFY TEXT "Edit or delete this file? " BT "_Edit|_Delete|_Cancel"'
  174.           IF RC = 0 THEN DO
  175.             IF RESULT = 0 THEN CALL list_files(att_files)
  176.             IF RESULT = 1 THEN CALL list_files(edit(entry.n))
  177.             IF RESULT = 2 THEN CALL list_files(del(entry.n, att_files))
  178.           END
  179.         END
  180.       END
  181.     END
  182.   END
  183.   CALL list_files(att_files)
  184. RETURN
  185. /*~!*/
  186.  
  187. /*!~ "Add"*/
  188. add:
  189.   files = ARG(1)
  190.   extrafiles = request_file(updir)
  191.   IF extrafiles = '' THEN allfiles = files
  192.   ELSE allfiles = files || sep || extrafiles
  193.  
  194.   IF POS(sep, allfiles) ~= 0 THEN DO
  195.     discard = POS(sep, allfiles)
  196.     DO UNTIL discard > 1
  197.       IF discard = 1 THEN allfiles = DELSTR(allfiles,1,1)
  198.       discard = POS(sep, allfiles)
  199.       IF discard = 0 THEN discard = 2
  200.     END
  201.   END
  202.  
  203.   dub = POS(sep||sep, allfiles)
  204.   DO UNTIL dub = 0
  205.     IF dub > 0 THEN allfiles = DELSTR(allfiles,dub,1)
  206.     dub = POS(sep||sep, allfiles)
  207.   END
  208. RETURN(allfiles)
  209. /*~!*/
  210.  
  211. /* !~ "Del"*/
  212. del:
  213.   delfile = ARG(1)
  214.   allattfiles = ARG(2)
  215.   posdel = POS(delfile, allattfiles)
  216.   IF posdel > 0 THEN DO
  217.     possep = POS(sep, allattfiles, posdel)
  218.     IF possep > posdel THEN remfile = possep - posdel + 1
  219.     ELSE remfile = LENGTH(delfile)
  220.     allattfiles = DELSTR(allattfiles, posdel, remfile)
  221.   END
  222. RETURN(allattfiles)
  223. /*~!*/
  224.  
  225. /*!~ "Edit"*/
  226. edit:
  227.   edfile = ARG(1)
  228.   file = SUBSTR(edfile, LASTPOS('/', edfile)+1)
  229.   path = SUBSTR(edfile,1, LASTPOS('/', edfile))
  230.  
  231.   ADDRESS(thorport)
  232.   'REQUESTFILE TITLE "Edit file." ID "'path'" IF "'file'" FP'
  233.   IF RC = 30 THEN DO
  234.     ADDRESS(thorport)
  235.     'REQUESTNOTIFY TEXT "'THOR.LASTERROR'" BT "_Ok"'
  236.     EXIT
  237.   END
  238.   IF RC = 5 THEN RETURN(att_files)
  239.   IF RC = 0 THEN DO
  240.     newfile = RESULT
  241.     part1 = SUBSTR(att_files,1 , POS(edfile, att_files)-1)
  242.     part2 = SUBSTR(att_files, POS(edfile, att_files)+LENGTH(edfile))
  243.     att_files = part1||newfile||part2
  244.   END
  245. RETURN(att_files)
  246. /*~!*/
  247.  
  248. /*!~ "Request_File" */
  249. request_file:
  250.   path    = ARG(1)
  251.   DROP selfile.
  252.   ADDRESS(thorport)
  253.   'REQUESTFILE TITLE "Select file(s) to attach." ID "'path'" FP MS OUTSTEM' selfile
  254.   IF (RC = 30) THEN DO
  255.     ADDRESS(thorport)
  256.     'REQUESTNOTIFY TEXT "'THOR.LASTERROR'" BT "_Ok"'
  257.     EXIT
  258.   END
  259.   IF RC = 5 THEN RETURN('')
  260.   IF RC = 0 THEN DO
  261.     fls = ''
  262.     IF selfile.COUNT > 1 THEN DO
  263.       DO fl = 1 TO selfile.COUNT
  264.         fls = fls || sep || selfile.fl
  265.       END
  266.     END
  267.     ELSE fls = selfile.1
  268.   END
  269. RETURN(fls)
  270. /*~!*/
  271.  
  272. /*!~ "Write_Event" */
  273. Write_event:
  274.   files = ARG(1)
  275.   ADDRESS BBSREAD
  276.   DO i = BBSDATA.FIRSTEVENT TO BBSDATA.LASTEVENT
  277.     DROP MSGTAGS. MSGDATA.
  278.     'READBREVENT BBSNAME "'system'" EVENTNR 'i' TAGSSTEM MSGTAGS DATASTEM MSGDATA'
  279.     IF(RC ~= 0) THEN DO
  280.       ADDRESS(thorport)
  281.       'REQUESTNOTIFY TEXT "'BBSREAD.LASTERROR'" BT "_Ok"'
  282.       EXIT 5
  283.     END
  284.  
  285.     IF(filename = MSGTAGS.MSGFILE) THEN DO
  286.       IF files = '' THEN DROP MSGTAGS.LOCALFILE
  287.       ELSE MSGTAGS.LOCALFILE  = files
  288.       WRITEBREVENT BBSNAME '"'system'"' EVENT MSGDATA.EVENTTYPE STEM MSGTAGS UPDATEEVENTNR i
  289.       IF(RC ~= 0) THEN DO
  290.         ADDRESS(thorport)
  291.         'REQUESTNOTIFY TEXT "'BBSREAD.LASTERROR'" BT "_Ok"'
  292.         EXIT 5
  293.       END
  294.       EXIT
  295.     END
  296.   END
  297. RETURN
  298. /*~!*/
  299.  
  300. /*!~ "Archive" */
  301. archive:
  302.   allarcfiles = ARG(1)
  303.   IF allarcfiles = '' THEN DO
  304.      ADDRESS(thorport)
  305.      'REQUESTNOTIFY TEXT " You need to add files first." BT "_Ok"'
  306.      CALL list_files(allarcfiles)
  307.   END
  308.  
  309.   arc = 0
  310.   IF allarcfiles ~= '' THEN DO
  311.   parse_allarcfiles = allarcfiles
  312.     DO UNTIL parse_allarcfiles = ''
  313.       arc = arc + 1
  314.       PARSE VAR parse_allarcfiles atchfile '01'x parse_allarcfiles
  315.       arclst.arc = atchfile
  316.     END
  317.     arclst.count = arc
  318.   END
  319.  
  320.   ADDRESS(thorport)
  321.   DROP arcfiles.
  322.   'REQUESTLIST INSTEM' arclst 'OUTSTEM' arcfiles 'TITLE "Select file(s) to archive." SIZEGADGET DRAGSELECT MULTISELECT'
  323.   IF (RC = 30) THEN DO
  324.     'REQUESTNOTIFY TEXT "'THOR.LASTERROR'" BT "_Ok"'
  325.     EXIT
  326.   END
  327.   IF RC = 5 THEN RETURN(allarcfiles)
  328.   ELSE DO
  329.     file = '.lha'
  330.     path = updir
  331.     ADDRESS(thorport)
  332.     'REQUESTFILE TITLE "Edit file." ID "'path'" IF "'file'" FP'
  333.     IF RC = 30 THEN DO
  334.       ADDRESS(thorport)
  335.       'REQUESTNOTIFY TEXT "'THOR.LASTERROR'" BT "_Ok"'
  336.       EXIT
  337.     END
  338.     IF RC = 5 THEN RETURN(allarcfiles)
  339.     IF RC = 0 THEN DO
  340.       addarcfile = RESULT
  341.       allarcfiles = allarcfiles || sep || addarcfile
  342.       arc_files = ''
  343.       DO f = 1 to arcfiles.COUNT
  344.         allarcfiles = del(arcfiles.f, allarcfiles)
  345.         arc_files = arc_files' "'arcfiles.f'"'
  346.       END
  347.       ADDRESS COMMAND lhapath'lha' lhaoptions addarcfile arc_files
  348.     END
  349.   END
  350. RETURN(allarcfiles)
  351. /*~!*/
  352.